package com.polimi.meteocal.security;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ActionEvent;

import com.polimi.meteocal.business.control.InviteManager;
import com.polimi.meteocal.business.control.PartecipationManager;
import com.polimi.meteocal.business.control.UserManager;
import com.polimi.meteocal.business.entity.Ack;
import com.polimi.meteocal.business.entity.Event;
import com.polimi.meteocal.business.entity.Invite;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@ManagedBean
@SessionScoped
public class InvitesConfirmedBean implements Serializable {

	/**
	 * 
	 */
	@EJB
	InviteManager im;
	@EJB
	UserManager um;
	@EJB
	PartecipationManager pm;
	
	private static final long serialVersionUID = 1L;
	
	private List<Invite> invitesReceived;
	private List<Ack> acks;
	
	
	@PostConstruct
	public void init(){
		
		//Set invitesReceived
		this.setInvitesReceived(im.getUserInviteList());
		
		//Set acks
		Ack aFi= new Ack();
		List<Ack> acksForUser= new ArrayList<Ack>();
		
		for(Invite i: invitesReceived){
			if(pm.getPartecipation(i.getEvent().getId(), i.getUser1(), i.getUser2())!=null){
				aFi=pm.getPartecipation(i.getEvent().getId(), i.getUser1(), i.getUser2());
				acksForUser.add(aFi);
			}
		
		}
		
		this.acks= acksForUser;
		
		
		
	}
	
	
	
	public String homeRedirect(){
		return "calendarPage";
	}

	public List<Invite> getInvitesReceived() {
		return invitesReceived;
	}

	public void setInvitesReceived(List<Invite> invitesReceived) {
		this.invitesReceived = invitesReceived;
	}

	public List<Ack> getAcks() {
		return acks;
	}

	public void setAcks(List<Ack> acks) {
		this.acks = acks;
	}

}
